﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Referrer.aspx.cs" Inherits="CRMWeb.Pages.Admin.Referrer" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Referrer Lender</title>
    <link rel="stylesheet" type="text/css" href="/Css/CrmStyle.css" />
     <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/default/easyui.css" />
     <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/icon.css" />
     <script type="text/javascript" src="/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/EasyUI/jquery.easyui.min.js"></script>
   
</head>
<body>
    <table id="dgReferrer" title="Referrer"   style="width: 600%; height: 370px;overflow-y:auto;" toolbar="#toolbarReferrer" rownumbers="true" fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="ReferrerID" width="100px">Referrer ID</th>
                <th field="Referrer" width="500px">Referrer</th>
            </tr>
        </thead>
    </table>
    <div id="toolbarReferrer">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newReferrer()">New</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editReferrer()">Edit</a>
        <a id="lnkDelete" href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#dlgDelReferrer').dialog('open')" plain="true" iconcls="icon-remove" title="Delete Client">Delete</a>
    </div>
    <div id="dlgReferrer" class="easyui-dialog" style="width: 350px; height: 220px; padding: 10px 20px"
        closed="true" buttons="#dlg-buttons">
        <div class="ftitle">Referrer Information</div>
        <form id="fmReferrer" method="post" novalidate>
            <div class="fitem">
                <label style="width: 130px;">Referrer:</label>
                <input id="txtReferrer" style="width: 292px;" class="easyui-validatebox" required="true" />
                <input id="hdnReferrerID" value="" style="display: none" />
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlgReferrer').dialog('close')" style="float: left">Cancel</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveReferrer()">Save</a>
    </div>
    <div id="dlgDelReferrer" class="easyui-dialog" title="Confirm" style="width: 300px; height: 160px" closed="true" resizable="false" modal="true">
        <h4 style="text-align: center">Are you sure want to delete this Referrer?</h4>
        <div class="fitem" style="float: left; padding: 10px; margin-top: 10px">
            <a id="lnkDelRef" href="javascript:void(0)" class="easyui-linkbutton" onclick="deleteReferrer()" disabled="true">OK</a>
            <a id="lnkCancleRef" href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#dlgDelReferrer').dialog('close')" disabled="true">Cancel</a>
            <span id="spnanimate">
                <img id="deleteProgress" style="margin-left: 20px" src="../../Media/loading.gif" />
                <label id="lbltimeOu" style="margin-left: 20px">5</label>
            </span>
        </div>
    </div>
    <script type="text/javascript">

        $(document).ready(function () {
            $('#dlgDelReferrer').dialog({
                onOpen: function () {
                    startCounter(5);

                },
                onClose: function () {
                    $('#lnkDelRef').linkbutton('disable');
                    $('#lnkCancleRef').linkbutton('disable');
                    $('#spnanimate').show();
                    $('#lbltimeOu').html('');
                }
            });
        });


        function startCounter(limit) {
            setTimeout(function () {
                if (limit == 0) {
                    $('#lnkDelRef').linkbutton('enable');
                    $('#lnkCancleRef').linkbutton('enable');
                    $('#spnanimate').hide();

                }
                else {
                    $('#lbltimeOu').html(limit);
                    startCounter(limit - 1);
                }
            }, 1000);
        }


        var url;
        function newReferrer() {
            $('#dlgReferrer').dialog('open').dialog('setTitle', 'New Referrer');
            $('#fmReferrer').form('clear');
            $('#txtReferrer').val('');
            $('#hdnReferrerID').val('');
            url = '/WebServices/Referrer/ReferrerAdd';
        }
        window.onresize = function () {
            $('#dgReferrer').datagrid('resize', {
               // width: window.innerWidth,
                //height: window.innerHeight
            });
        }
        function editReferrer() {
            var row = $('#dgReferrer').datagrid('getSelected');
            if (row) {
                $('#dlgReferrer').dialog('open').dialog('setTitle', 'Edit OutSource Lender');
                $('#fmReferrer').form('load', row);
                $('#txtReferrer').val(row.Referrer);
                $('#hdnReferrerID').val(row.ReferrerID);
                url = '/WebServices/Referrer/ReferrerAdd?ReferrerID=' + row.ReferrerID;
            }
        }
        function deleteReferrer() {
            var row = $('#dgReferrer').datagrid('getSelected');
            if (row) {
                $.ajax({
                    url: '/WebServices/Referrer.ashx',
                    type: 'POST',
                    data: {
                        method: 'ReferrerDelete',
                        args: { ReferrerID: row.ReferrerID }

                    },
                    success: function (data) {
                        $('#dgReferrer').datagrid('reload');
                        $('#dlgDelReferrer').dialog('close');
                    }
                });
            }
        }
        function saveReferrer() {
            var strReferrer = $('#txtReferrer').val();
            var ReferrerID = $('#hdnReferrerID').val();

            if (ReferrerID != '') {
                if (strReferrer != '') {
                    $.ajax({
                        url: '/WebServices/Referrer.ashx',
                        type: 'POST',
                        data: {
                            method: 'ReferrerEdit',
                            args: { ReferrerID: ReferrerID, Referrer: strReferrer }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgReferrer').dialog('close');
                                $('#dgReferrer').datagrid('reload');
                            }
                            else {
                                alert('Referrer already exist');
                            }
                        }
                    });
                }
            }
            else {
                if (strReferrer != '') {
                    $.ajax({
                        url: '/WebServices/Referrer.ashx',
                        type: 'POST',
                        data: {
                            method: 'ReferrerAdd',
                            args: { Referrer: strReferrer }
                        },
                        success: function (data) {
                            if (data == 1) {
                                $('#dlgReferrer').dialog('close');
                                $('#dgReferrer').datagrid('reload');
                            }
                            else {
                                alert('Referrer already exist.');
                            }
                        }
                    });
                }
            }
        }

        $(document).ready(function () {
            $('#dgReferrer').datagrid({
                url:'/WebServices/Referrer.ashx?method=ReferrerSelect',
                onDblClickRow: function (index, rowdata) {
                    editReferrer();
                }
            });
        });

    </script>
</body>
</html>

